<template>
	<view class="width_drawal fs-30">
		<view class="p-20">
			<view class="bg-info-1 rd-20 p-20 my-20">
				<view class="">输入提现金额</view>
				<view class="flex-between-center u-border-bottom mb-20">
					<view class="flex-y-center fs-64 py-20">
						<span class="fs-40 mr-20">￥</span>
						<input class="fs-64" type="digit" v-model="money" placeholder-class="fs-64 c-999" placeholder="0.00">
					</view>
					<view class="text-nowrap p-20 color-primary" @click="allBtn">全部提现</view>
				</view>
				
				<view class="flex-between-center u-border-bottom py-20"><span>可提现金额：</span><span class="color-success">{{wait_withdrawal}}元</span></view>
				
				<view class="flex-between-center u-border-bottom py-20 c-666"><span>税率：</span><span>{{withdraw_config.withdrawal_tax_rate}}%</span></view>
				<view class="flex-between-center u-border-bottom py-20 c-666"><span>到账金额：</span><span>{{(money*withdraw_config.withdrawal_tax_rate_text).toFixed(2)}}</span></view>
			</view>
			
			<view class="bg-info-1 rd-20 p-20 my-20 fs-30">
				<view class="mb-20">提现账户</view>
				
				<view class="flex-between-center c-666 my-20 py-20 u-border-bottom">
					<view class="">收款人姓名</view>
					<input class="text-right" type="text" v-model="collection_name" placeholder-class="c-999" placeholder="请输入收款人姓名">
				</view>
				
				<view class="flex-between-center c-666 my-20 py-20 u-border-bottom">
					<view class="">收款类型</view>
					<view>
						<u-radio-group v-model="type">
						    <u-radio class="mr-20" :key="1" label="支付宝" :name="1"></u-radio>
						    <u-radio :key="2" label="银行卡" :name="2"></u-radio>
						  </u-radio-group>
					</view>
				</view>
				
				<view v-if="type==1" class="flex-between-center c-666 my-20 py-20 u-border-bottom">
					<view class="">支付宝账号</view>
					<view class="">{{user_account.zfb_account}}</view>
				</view>
				
				<view v-if="type==2">
					<view class="flex-between-center c-666 my-20 py-20 u-border-bottom">
						<view class="">银行卡账号</view>
						<view class="">{{user_account.bank_card}}</view>
					</view>
					
					<view class="flex-between-center c-666 my-20 py-20 u-border-bottom">
						<view class="">开户行</view>
						<view class="">{{user_account.bank_account}}</view>
					</view>
				</view>
			</view>
		</view>
		
		<BottomBtn title='申请提现' @submit='submitBtn' v-if="withdraw_config.withdrawal_switch === '1'"></BottomBtn>
		<BottomBtn title='提现关闭中'v-else></BottomBtn>
	</view>
</template>

<script>
	import BottomBtn from '@/components/bottom_btn/bottom_btn.vue';
	export default {
		components:{
			BottomBtn
		},
		data() {
			return {
				type:1,//类型:1=支付宝,2=银行卡
				wait_withdrawal:'0.00',
				collection_name:'',
				money:'',
				user_account:{
					username:'',
					zfb_account:'',
					bank_card:'',
					bank_account:'',
				},
				withdraw_config:{
					withdrawal_switch:'1',//提现开关
					withdrawal_start_time:'',//每天开始时间
					withdrawal_end_time:'',//每天结束时间
					withdrawal_day_num:'',//每日最多提现次数
					withdrawal_min_money:'',//最小提现金额
					withdrawal_tax_rate:'',//费率
				},
			};
		},
		onLoad(opt) {
			this.wait_withdrawal=opt.money
		},
		onShow() {
			this.userInfo()
			this.getWithdrawConfig()
		},
		methods:{
			allBtn(){
				this.money=this.wait_withdrawal
			},
			getWithdrawConfig(){
				this.$httpApi.getWithdrawConfig().then((res) => {
					if (res.code == 1) {
						this.withdraw_config = res.data.config
					}
				})
			},
			// 获取用户信息
			userInfo(){
				var that = this
				that.$tips.showLoading('加载中')
				that.$httpApi.userShop().then((res)=>{
					that.$tips.hideLoading()
					if(res.code==1){
						that.wait_withdrawal = res.data.userinfo.money;
						if(res.data.userinfo.user_account){
							that.user_account = res.data.userinfo.user_account;
							that.collection_name = res.data.userinfo.user_account.username;
						}
					}
				})
			},
			submitBtn(){
				var that = this
				if(that.money=='' || that.money*1==0){
					that.$tips.showToast('请输入提现金额')
					return
				}else{
					if(that.money < that.withdraw_config.withdrawal_min_money){
						that.$tips.showToast('最少提现金额为'+that.withdraw_config.withdrawal_min_money);
						return
					}
					that.$tips.showLoading('提交中')
					var params = {
						money:that.money,
						collection_name:that.collection_name,
						type:that.type,
						
					}
					that.$httpApi.userWithdrawcash(params).then((res)=>{
						that.$tips.hideLoading()
						if(res.code==1){
							that.$tips.showToast('申请成功')
							setTimeout(function(){
								uni.navigateBack()
							},2000)
						}
					})
				}
			},
		}
	}
</script>

<style lang="less">
	
</style>
